new Vue({
    el: '#app',
    data() {
      return {
        form: {
          page: 1,			//页数
          limit: 10,		//每页数据条数
          // Article_Name: "",
          // Activity: ""
          // id: '',
        },
        formData: {},
        tableData: [
          // {
          //   Activity:'0', 
          //   Article_Name: '上海硫磺皂125克/威王魔力果净520克/蓝月亮护理洗衣液500g/雕牌全效加浓洗洁精500克',
          //   Start_Date: '2024-01-17 22:35:06',
          //   End_Date: '2024-03-28 00:00:00',
          //   Integral_Unit_Price_SerialNumber:"H00000000000020",
          //   Children:{
          //     integral_unitprice_detail:[]
          //   }
          // },
          // {
          //   Activity:'0', 
          //   Article_Name: '上海硫磺皂125克/威王魔力果净520克/蓝月亮护理洗衣液500g/雕牌全效加浓洗洁精500克',
          //   Start_Date: '2024-01-17 22:35:06',
          //   End_Date: '2024-03-28 00:00:00',
          //   Integral_Unit_Price_SerialNumber:"H00000000000020",
          //   Children:{
          //     integral_unitprice_detail:[]
          //   }
          // },
          // {
          //   Activity:'0', 
          //   Article_Name: '上海硫磺皂125克/威王魔力果净520克/蓝月亮护理洗衣液500g/雕牌全效加浓洗洁精500克',
          //   Start_Date: '2024-01-17 22:35:06',
          //   End_Date: '2024-03-28 00:00:00',
          //   Integral_Unit_Price_SerialNumber:"H00000000000020",
          //   Children:{
          //     integral_unitprice_detail:[]
          //   }
          // },
          // {
          //   Activity:'0', 
          //   Article_Name: '上海硫磺皂125克/威王魔力果净520克/蓝月亮护理洗衣液500g/雕牌全效加浓洗洁精500克',
          //   Start_Date: '2024-01-17 22:35:06',
          //   End_Date: '2024-03-28 00:00:00',
          //   Integral_Unit_Price_SerialNumber:"H00000000000020",
          //   Children:{
          //     integral_unitprice_detail:[]
          //   }
          // },
        ],
        tableData2: [],
        //表格数据
        total: 1,
        dialogForm: false,
        title: '',
        multipleSelection: []
      }
    },
    mounted() {
      this.getList(this.form)
      // console.log(DomainName);
    },
    methods: {
      onSerach() {				//查询方法
        this.getList(this.form)
      },
      addContract() {
        console.log("跳转")
      },
      handleSizeChange(val) {
        this.form.page = 1;
        this.form.limit = val;
        this.getList(this.form)
      },
      handleCurrentChange(val) {
        this.form.page = val;
        this.getList(this.form)
      },
      getList(data) {
        let _this = this
        $.ajax({
          type: 'POST',
          data:{
            Interface: DomainName1 +'/articleInfo/getIntegralUnitprice' ,
            Methods: 'POST',
            Query: JSON.stringify(data)
          },
          url: DomainName + '/getServerInquiryAction?token=' + $.cookie("token"),
          success: function (data) {
            console.log('data',data);
            _this.tableData = data.tableData;
            _this.total = Number(data.total);
            console.log(_this.tableData)
          },
          complete: function (XMLHttpRequest) {
            _this.loading = false
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          },
          dataType: "json"
        });
      },
      expandChange(row) {
        let data = row.Integral_Unit_Price_SerialNumber
        let _this = this
        $.ajax({
          type: 'POST',
          data: {
            Integral_Unit_Price_SerialNumber: data
          },
          url: DomainName1 + '/getIntegralUnitpriceDetail?token=' + $.cookie("token"),
          success: function (data) {
            console.log('data1', data);
            row.Children.integral_unitprice_detail = data.Data;
          },
          complete: function (XMLHttpRequest) {
            _this.loading = false
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          },
          dataType: "json"
        });
      },
      addEnterprise() {
        window.location.href = './Add.html'
      },
      showMember(Integral_Unit_Price_SerialNumber) {
        sessionStorage.setItem("Integral_Unit_Price_SerialNumber", Integral_Unit_Price_SerialNumber)
        window.location.href = './show.html?Integral_Unit_Price_SerialNumber=' + Integral_Unit_Price_SerialNumber
      },
      editMember(Integral_Unit_Price_SerialNumber) {
        sessionStorage.setItem("Integral_Unit_Price_SerialNumber", Integral_Unit_Price_SerialNumber)
        window.location.href = './Edit.html?Integral_Unit_Price_SerialNumber=' + Integral_Unit_Price_SerialNumber
      },
      onExcel() {
        /* generate workbook object from table */
        //  .table要导出的是哪一个表格
        var wb = XLSX.utils.table_to_book(document.querySelector("#out-table"));
        /* get binary string as output */
        var wbout = XLSX.write(wb, {
          bookType: "xlsx",
          bookSST: true,
          type: "array"
        });
        try {
          //  name+'.xlsx'表示导出的excel表格名字
          saveAs(
            new Blob([wbout], {
              type: "application/octet-stream"
            }),
            "销售价格单" + ".xlsx"
          );
        } catch (e) {
          if (typeof console !== "undefined") console.log(e, wbout);
        }
        return wbout;
      },
      deletMember(Integral_Unit_Price_SerialNumber) {
        this.$confirm('此操作将删除该销售价格单, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          this.delete(Integral_Unit_Price_SerialNumber);
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      delete(Integral_Unit_Price_SerialNumber) {
        const _this = this
        $.ajax({
          url: DomainName + '/SalesUnitpriceId',
          type: 'POST',
          data: { Data: Integral_Unit_Price_SerialNumber },
          success: function (res) {
            if (res.length == 1) {
              res[0].Row_Status = '1'
              let data = { Data: JSON.stringify({ Modify: { sales_unitprice: [res[0]] } }) };
              $.ajax({
                url: DomainName + '/GoodsFileEdit',
                type: 'POST',
                data,
                success: function (re) {
                  if (re.Status == "success") {
                    _this.$message.success("作废成功")
                    _this.getList();
                  }
                },
                error: function () {
                  _this.$message.error("删除失败，请稍后再试")
                },
                complete: function (XMLHttpRequest) {
                  _this.loading = false
                  if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                    window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                  }
                }
              })
            }
          }
        })
      },
      // 子表删除
      deletMember2(row) {
        const _this = this;
        let Primary_Key_Name = "Integral_Unit_Price_Detail_SerialNumber";
        let Primary_Key = row.Integral_Unit_Price_Detail_SerialNumber;
        this.$confirm('此操作将删除该商品信息, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          $.ajax({
            url: DomainName + '/getInquiryIDOriginal?token=' + $.cookie('token'),
            type: 'POST',
            data: {
              Primary_Key_Name,
              Primary_Key,
              Data: "integral_unitprice_detail",
            },
            error: function (array) {
              console.log(array);
              _this.$message.error("删除失败，请稍后再试")
            },
            complete: function (XMLHttpRequest) {
              _this.loading = false
              if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
              }
            },
            success: function (res) {
              _this.Delete(res);
            }
          })
        }).catch(() => {
          this.$message({
            type: 'warning',
            message: '已取消删除'
          });
        });
      },
      //删除
      Delete(row) {
        const _this = this;
        let rowData = [];
        // 判断 row 的类型
        if (Array.isArray(row)) {
          // 如果是数组，则取第一个元素作为 rowData
          rowData = [...row];
        } else {
          // 否则，直接使用 row 作为 rowData
          rowData.push(
            row
          );
        }
        rowData.forEach((item) => {
          item.Row_Status = '1'
        })
        let data = {
          Data: JSON.stringify({
            Modify: { integral_unitprice_detail: rowData }
          })
        };
        $.ajax({
          url: DomainName + '/getEditAction?token=' + $.cookie('token'),
          type: 'POST',
          data,
          error: function (array) {
            console.log(array);
            _this.$message.error("删除失败，请稍后再试")
          },
          complete: function (XMLHttpRequest) {
            _this.loading = false
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          },
          success: function (res) {
            if (res.Status == 'success') {
              _this.$message({
                type: 'success',
                message: '删除成功!'
              });
            }
          }
        })
      }
    },
  })